#include "Plotter.h"
#include "GUI/SimpleTest.h"
using namespace std;

void runPlotterScript(istream& input) {
    bool pendown=false;
    double x0=0,y0=0;
    PenStyle penstyle={1,"black"};
    for (string line; getline(input, line);) {
        line = toUpperCase(line);
        Vector<string> cmd = stringSplit(line, " ");

        if(cmd[0]=="PENDOWN"){
            pendown=true;
        }
        else if(cmd[0]=="PENUP"){
            pendown=false;
        }
        else if(cmd[0]=="MOVEABS"){
            double x1=stringToReal(cmd[1]);
            double y1=stringToReal(cmd[2]);
            if(pendown){
            drawLine(x0,y0, x1,y1,
                     penstyle);
            }
            x0=x1;
            y0=y1;
        }
        else if(cmd[0]=="MOVEREL"){
            double x1=x0+stringToReal(cmd[1]);
            double y1=y0+stringToReal(cmd[2]);
            if(pendown){
                drawLine(x0,y0, x1,y1,
                         penstyle);
            }
            x0=x1;
            y0=y1;
        }
        else if(cmd[0]=="PENCOLOR"){
            penstyle.color=cmd[1];
        }
        else if(cmd[0]=="PENWIDTH"){

            penstyle.width=stringToReal(cmd[1]);
        }
    }
}

